#include "PeopleWindow.h"
#include "ChatWindow.h"
#include "WindowManager.h"
#include "ui_PeopleWindow.h"
#include "Satory.h"
PeopleWindow::PeopleWindow(QWidget *parent) :
    BaseWindow(parent),
    ui(new Ui::PeopleWindow)
{
    ui->setupUi(this);
    connect(ui->AddButton,SIGNAL(clicked()),this,SLOT(OnAddClick()));
}
void PeopleWindow::OnAddClick()
{
    WindowManager::GetInstance()->ShowWindow(WindowManager::FINDWINDOW);
}
void PeopleWindow::OnItemClicked(QListWidgetItem* item)
{
    ChatWindow* win=dynamic_cast<ChatWindow*>(WindowManager::GetInstance()->ShowWindow(WindowManager::CHATWINDOW));
    win->setWindowTitle(item->text());
    Dream* dream=Satory::GetInstance()->GetDream(item->text());
    win->SetDream(dream);
    dream->AttachUi(Dream::CHAT,win);

}

QListWidgetItem* PeopleWindow::AddPerson(QString userId,QString status)
{
    ui->Roster->addItem(userId);
    QListWidgetItem* item=ui->Roster->item(0);

    connect(ui->Roster,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(OnItemClicked(QListWidgetItem*)));
    return item;
}

PeopleWindow::~PeopleWindow()
{
    delete ui;
}

